package linwen.wang;



import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
import com.baomidou.mybatisplus.generator.fill.Column;
import com.baomidou.mybatisplus.generator.fill.Property;


import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

/**
 * @author wlw
 * @date 2023/4/5 10:42 AM
 */
public class CodeGenerator {
    /**
     * RUN THIS
     */
    public static void main(String[] args) {

        //  获取用户程序当前路径
        String projectPath= System.getProperty("user.dir");
        projectPath += "/springboot_13_joinMemory";
        System.out.println(projectPath);
        // 设置输出到的目录
        String out = projectPath + "/src/main/java";
//        设置mapper.xml生成路径
        String xmlOut = projectPath + "/src/main/resources/linwen/wang/dao";

        FastAutoGenerator.create("jdbc:mysql://localhost:3306/joinMemory?serverTimezone=Asia/Shanghai", "root", "123456789")
                .globalConfig(builder -> {
                    builder.author("wlw") // 设置作者
                            .fileOverride() // 覆盖已生成文件
                            .outputDir(out); // 指定输出目录
                })
                .packageConfig(builder -> {
                    builder.parent("linwen.wang") // 设置父包名
                            .entity("entity")
                            .service("service")
                            .serviceImpl("service.impl")
                            .mapper("mapper")
                            .xml("mapper.xml")
                            .controller("controller")
                            .pathInfo(Collections.singletonMap(OutputFile.xml, xmlOut)); // 设置mapperXml生成路径
                })
                .strategyConfig(builder -> {
                    builder
                            // .addInclude("address_t") // 设置需要生成的表名

                            .enableSkipView()
                            .addTableSuffix("_t")
                            .entityBuilder()
                            .superClass("linwen.wang.entity.BaseEntity")
                            //.disableSerialVersionUID()
                            .enableLombok()
                            .enableTableFieldAnnotation()
                            //.enableActiveRecord()
                            .versionColumnName("version")
                            .versionPropertyName("version")
                            .logicDeleteColumnName("deleted")
                            .logicDeletePropertyName("deleteFlag")
                            .columnNaming(NamingStrategy.underline_to_camel)
                            .addSuperEntityColumns("id", "created_by", "created_time", "updated_by", "updated_time")
                            .addTableFills(new Column("created_time", FieldFill.INSERT))
                            .addTableFills(new Property("updatedTime", FieldFill.INSERT_UPDATE))
                            .idType(IdType.AUTO)
                    ;
                            // .addTablePrefix("blog_", "c_"); // 设置过滤表前缀

                })
                .templateEngine(new FreemarkerTemplateEngine()) // 使用Freemarker引擎模板，默认的是Velocity引擎模板
                .execute();


    }

}
